﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceProcess;

namespace SysTrayPrg
{

    /// <summary>
    /// <para>All Posible Commands, which can be sent to the service</para>
    /// <para>unkown: if no valid command was sent</para>
    /// <para>ReloadSettings: read Settings <example>Example: Interval</example></para>
    /// <para>Search: start a new Search</para>
    /// <para>ChangeConfigFile: Read the new Path for the ConfigFile</para>
    /// <para>Pause: Pauses the Service</para>
    /// <para>Continue: Continues the Service</para>
    /// <para>Stop: Permanently Stops the Service</para>
    /// </summary>
    enum Command { unknown = 127, ReloadSettings, Search, ChangeConfigFile, Pause, Continue, Stop }
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void contextMenuStripNotifyIcon_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Name == "toolStripMenuItemExit")
                Application.Exit();
            try
            {
                ServiceController sc = new ServiceController(notifyIcon.ContextMenuStrip.Items[0].Text);
                switch (e.ClickedItem.Name)
                {
                    case "toolStripMenuItemFullScan":
                        sc.ExecuteCommand((int)Command.Search);
                        break;
                    case "toolStripMenuItemContinue":
                        sc.ExecuteCommand((int)Command.Continue);
                        break;
                    case "toolStripMenuItemPause":
                        sc.ExecuteCommand((int)Command.Pause);
                        break;
                    case "toolStripMenuItemStop":
                        sc.ExecuteCommand((int)Command.Stop);
                        break;
                    default:
                        break;
                }
            }
            catch { }
        }
    }
}
